#include "Vector.h"

#include <math.h>

using namespace Math;

/** The X axis */
const Vector& Vector::X=Vector(1.0f,0.0f,0.0f);
/** The Y axis */
const Vector& Vector::Y=Vector(0.0f,1.0f,0.0f);
/** The Z axis*/
const Vector& Vector::Z=Vector(0.0f,0.0f,1.0f);

//Default constructor
Vector::Vector(float x, float y, float z):Point(x,y,z)
{
}

//Copy constructor
Vector::Vector(const Vector& v):Point(v.x(),v.y(),v.z())
{
}

//Construct a vector from 2 points
Vector::Vector(const Point& p1, const Point& p2):Point(p2.x()-p1.x(),p2.y()-p1.y(),p2.z()-p1.z())
{
}

/**********
* GETTERS *
**********/
float Vector::length()
{
	return sqrt(_x*_x+_y*_y+_z*_z); //evil
}

float Vector::magnitude()
{
	return length();
}

//Returns a unit vector, without modifying the current vector
Vector Vector::unit()
{
	Vector v(*this);

	v.normalize();

	return v;
}

/*************
* OPERATIONS *
*************/

void Vector::normalize()
{
	float l=length();

	_x/=l;
	_y/=l;
	_z/=l;
}
